package com.cn.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Comparator;
import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
    * 菜品及套餐分类
    */
@ApiModel(value="com-cn-pojo-Category")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "category")
@EqualsAndHashCode(callSuper = false)
public class Category implements Comparator<Category>{
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.INPUT)
    @ApiModelProperty(value="主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 父级id
     */
    @TableField(value = "pid")
    @ApiModelProperty(value="父级id")

    private Long pid;
    /**
     * 类型   1 菜品分类 2 套餐分类
     */
    @TableField(value = "level")
    @ApiModelProperty(value="主键")
    private Integer level;

    /**
     * 分类名称
     */
    @TableField(value = "name")
    @ApiModelProperty(value="分类名称")
    private String name;

    @TableField(value = "img")
    @ApiModelProperty(value="菜品照片")
    private String img;
    /**
     * 顺序
     */
    @TableField(value = "sort")
    @ApiModelProperty(value="顺序")
    private Integer sort;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    @ApiModelProperty(value="创建时间")
    private Date createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    @ApiModelProperty(value="更新时间")
    private Date updateTime;

    /**
     * 创建人
     */
    @TableField(value = "create_user")
    @ApiModelProperty(value="创建人")
    private Long createUser;

    @TableField(exist = false)
    @ApiModelProperty(value="上级菜品名称")
    private String cateName;

    /**
     * 修改人
     */
    @TableField(value = "update_user")
    @ApiModelProperty(value="修改人")
    private Long updateUser;

    //因为此字段不属于表内字段，所以加上 @TableField(exist = false)
    @TableField(exist = false)
    private List<Category> childMenus;



    /**
     * 排序，根据order排序
     */
    public static Comparator<Category> order(){
        Comparator<Category> comparator=(o1, o2) -> {
            if (o1.getSort()!=o2.getSort())
            {
                return (int) (o1.getSort() - o2.getSort());
            }
            return 0;
        };
        return comparator;
    }

    public static final String COL_ID = "id";

    public static final String COL_PID = "pid";

    public static final String COL_LEVEL = "level";

    public static final String COL_NAME = "name";

    public static final String COL_SORT = "sort";

    public static final String COL_CREATE_TIME = "create_time";

    public static final String COL_UPDATE_TIME = "update_time";

    public static final String COL_CREATE_USER = "create_user";

    public static final String COL_UPDATE_USER = "update_user";

    @Override
    public int compare(Category o1, Category o2) {
        if(o1.getSort()<o2.getSort()){
            return -1;
        }else{
            return 1;
        }

    }
}